﻿using GRPCClass;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using static GRPCClass.gRPC;

namespace SdtpsLibrary
{
    /// <summary>
    /// 任务发送到执行节点
    /// </summary>
    public class TaskSendNode: ITaskSendNode
    {
        private Worker _AppWorker;
        SdtpsRPCSDK.GRPCClient mygc = new SdtpsRPCSDK.GRPCClient();
        public  Worker AppWorker
        {
            get
            {
                return _AppWorker;
            }
            set
            {
                _AppWorker = value;
            }
        }

        /// <summary>
        /// 发送到节点
        /// </summary>
        /// <param name="nworker"></param>
        /// <param name="request"></param>
        /// <returns></returns>
        public  string SendToNode(TaskRequest request)
        {
            try
            { 
                mygc.Servadd = string.Format("{0}:{1}", _AppWorker.Host, _AppWorker.Port);
                mygc.AllotTask(request);

                return "";
            }
            catch (Exception cw)
            {
                return cw.Message;
            }
        }
    }
}
